import { FetchTVWallItem, FetchTVWallListItem, SaveTVWallItem } from '@/api/sysConfig/tvWallConfig/interface'
import { ITVWallItem, TVWallConfigProps } from './interface'

export const transTVWallList = (list: FetchTVWallListItem[]): ITVWallItem[] =>
	list.map((item) => ({ tvWallTemplateId: item.id, name: item.name }))

export const transTVWallEditInfo = (data?: FetchTVWallItem): TVWallConfigProps => {
	return data
		? {
				isApply: true,
				tvWallTemplateId: data.style_id,
				name: data.name,
				lineNum: data.layout_y,
				columnNum: data.layout_x,
				boxList: data.details.map((item) => ({
					parent_box_width: item.parent_box_width,
					box_x: item.box_x,
					box_y: item.box_y,
					box_width: item.box_width,
					box_height: item.box_height,
					hdu_id: item.hdu_id.split('_')[0],
					hdu_alias: item.hdu_alias ?? '',
					channel_id: item.hdu_id.split('_')[1],
				})),
		  }
		: {
				isApply: false,
				tvWallTemplateId: '',
				name: '',
				lineNum: 1,
				columnNum: 1,
				boxList: [],
		  }
}

export const transSaveTVWallParam = (data: TVWallConfigProps): SaveTVWallItem => ({
	name: data.name,
	layout_x: data.columnNum,
	layout_y: data.lineNum,
	details: data.boxList.map((item) => ({
		parent_box_width: item.parent_box_width,
		box_x: item.box_x,
		box_y: item.box_y,
		box_height: item.box_height,
		box_width: item.box_width,
		hdu_id: item.hdu_id && item.channel_id ? item.hdu_id + '_' + item.channel_id : '',
		hdu_alias: item.hdu_alias,
	})),
})
